home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / lib / Rectangle.h < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  79 lines

  1. #ifndef    RECTANGLE_H
  2. #define    RECTANGLE_H
  3.  
  4. /*$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Rectangle.h,v 3.0 90/05/20 00:20:59 kgorlen Rel $*/
  5.  
  6. /* Rectangle.h -- declarations for class Rectangle
  7.  
  8.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  9.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  10.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  11.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  12.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  13.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  14.  
  15. Author:
  16.     K. E. Gorlen
  17.     Computer Systems Laboratory, DCRT
  18.     National Institutes of Health
  19.     Bethesda, MD 20892
  20.  
  21. $Log:    Rectangle.h,v $
  22.  * Revision 3.0  90/05/20  00:20:59  kgorlen
  23.  * Release for 1st edition.
  24.  * 
  25. */
  26.  
  27. #include "Object.h"
  28. #include "Point.h"
  29. #include <math.h>
  30.  
  31. class Rectangle: public VIRTUAL Object {
  32.     DECLARE_MEMBERS(Rectangle);
  33.     Point tl;        // top left corner (origin)
  34.     Point br;        // bottom right corner (corner)
  35. protected:        // storer() functions for object I/O
  36.     virtual void storer(OIOofd&) const;
  37.     virtual void storer(OIOout&) const;
  38. public:
  39.     Rectangle(int left=0, int top=0, int height=0, int width=0);
  40.     Rectangle(const Point&, const Point&);
  41.     Rectangle(const Rectangle&);
  42.     Point origin() const        { return tl; }
  43.     Point origin(const Point& p)    { return tl = p; }
  44.     Point corner() const        { return br; }
  45.     Point corner(const Point& p)    { return br = p; }
  46.     Point topLeft() const        { return tl; }
  47.     Point topCenter() const        { return Point((br.x()+tl.x())/2,tl.y()); }
  48.     Point topRight() const        { return Point(br.x(),tl.y()); }
  49.     Point rightCenter() const    { return Point(br.x(),(br.y()+tl.y())/2); }
  50.     Point bottomRight() const    { return br; }
  51.     Point bottomCenter() const    { return Point((br.x()+tl.x())/2,br.y()); }
  52.     Point bottomLeft() const    { return Point(tl.x(),br.y()); }
  53.     Point leftCenter() const    { return Point(tl.x(),(br.y()+tl.y())/2); }
  54.     Point center() const        { return Point((br.x()+tl.x())/2,(br.y()+tl.y())/2); }
  55.     Point extent() const        { return Point(br.x()-tl.x(),br.y()-tl.y()); }
  56.     int area() const        { return (br.x()-tl.x())*(br.y()-tl.y()); }
  57.     int width() const        { return br.x()-tl.x(); }
  58.     int height() const        { return br.y()-tl.y(); }
  59.     bool operator==(const Rectangle&) const;
  60.     bool operator!=(const Rectangle& r) const    { return !(*this==r); }
  61.     Rectangle operator&&(const Rectangle&) const;    // intersection 
  62.     Rectangle operator||(const Rectangle&) const;    // union 
  63.     void operator+=(const Point&);            // translate 
  64.     void operator-=(const Point&);
  65.     bool contains(const Point&) const;
  66.     bool contains(const Rectangle&) const;
  67.     bool intersects(const Rectangle&) const;
  68.     void moveTo(const Point&);
  69.     virtual void deepenShallowCopy();    // {}
  70.     virtual unsigned hash() const;
  71.     virtual bool isEqual(const Object&) const;    // equality test 
  72.     virtual void printOn(ostream& strm =cout) const;
  73.     virtual const Class* species() const;
  74. private:                // shouldNotImplement()
  75.     virtual int compare(const Object&) const;
  76. };
  77.  
  78. #endif
  79.